/**
 * 
 */
package edu.cornell.cs.lsi.projone.service;

import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;

import edu.cornell.cs.lsi.projone.model.ServerData;

/**
 * @author poornima
 * 
 */
public class ServerDataManager {

	private static ServerDataManager serverDataMgr = null;
	private Map<String, ServerData> serverData;

	private ServerDataManager() {
		serverData = new HashMap<String, ServerData>();
	}

	public static ServerDataManager getInstance() {
		if (serverDataMgr == null) {
			serverDataMgr = new ServerDataManager();
		}
		return serverDataMgr;
	}

	public Map<String, ServerData> getServerDataSet() {
		return this.serverData;
	}

	public void addServerInfo(ServerData serverData) {
		if (serverData == null || serverData.getIpHostName() == null
				|| StringUtils.isEmpty(serverData.getIpHostName())) {
			System.out.println("Error: server info is not set.");
			return;
		}
		this.serverData.put(serverData.getIpHostName(), serverData);
	}

	public ServerData getServerInfo(String hostName) {
		if (hostName == null || StringUtils.isEmpty(hostName)) {
			System.out.println("Error: the incoming hostname is not set.");
			return null;
		}
		return this.serverData.get(hostName);
	}

	public void addServerInfo(List<ServerData> serverDataList) {
		if (serverDataList == null || serverDataList.isEmpty()) {
			return;
		}

		this.serverData = new HashMap<String, ServerData>();
		for (ServerData serverData : serverDataList) {
			addServerInfo(serverData);
		}
	}

	public Collection<ServerData> getServerDataList() {

		return this.serverData.values();

	}
}